﻿using UnityEngine;
using UnityEngine.UIElements;
using winS.Unity;
using winS.UnityEditor.UIElement;
using Label = winS.UnityEditor.UIElement.Label;

namespace winS.UnityEditor.ProcessEditor
{
    internal class ZoomControl : VisualElement
    {
        private readonly Label valueLabel;
        private readonly VisualElement box;
        private readonly VisualElement border;

        public ZoomControl()
        {
            style.position = Position.Absolute;
            style.right = style.top = 8f;

            Add(border = EditorElementUtility.elementFactory.CreateEditorElement());
            border.style.SetBorder(Color.green, 1f);
            border.style.SetSize(40f);

            border.Add(box = EditorElementUtility.elementFactory.CreateEditorElement(new Color32(0, 160, 0, 255)));
            box.style.flexGrow = 1f;

            Add(valueLabel = EditorElementUtility.elementFactory.CreateLabel());
            valueLabel.style.unityTextAlign = TextAnchor.MiddleCenter;
        }

        public void SetZoom(float ratio)
        {
            box.style.SetScale(ratio);
            valueLabel.text = Math.Remap(ratio, 0f, 1f, 0f, 2f).ToString("f2");
        }
    }
}
